﻿using Flurl;
using Flurl.Http;
using Modules.Units;
using Sorting.App.Models;
using Sorting.App.Models.Entity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Sorting.App.Services
{

    /// <summary>
    /// 贴签的服务处理
    /// </summary>
    public class TQService
    {

        private ServiceApis serviceApis = new ServiceApis();

        /// <summary>
        /// 获取贴签机中的病区信息
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<TQSnNoModel> GetTQWareNoBySn(string SnNo)
        {

            var res= await serviceApis.GetTQWareNoBySnApi
                 .WithOAuthBearerToken( AppsettingUnits.Token)
                       .SetQueryParams(new
                       {
                           SnNo = SnNo,
                       }).PostAsync()
                       .ReceiveJson<ResfulModel<TQSnNoModel>>();

            return res.data;

        }



        /// <summary>
        /// 获取贴签机中的病区信息(从同不过来的表)
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<BarcodeWardDto> GetTQWareNoBySnForAsyn(string SnNo)
        {
            try
            {
                var res = await serviceApis.GetTQWareNoBySnForAsynApi
           .WithOAuthBearerToken(AppsettingUnits.Token)
                 .SetQueryParams(new
                 {
                     SnNo = SnNo,
                 }).PostAsync()
                 .ReceiveJson<ResfulModel<BarcodeWardDto>>();

                return res.data;

            }
            catch (Exception ex)
            {

                throw;
            }


        }


        /// <summary>
        /// 获取贴签中的所有病区信息
        /// </summary>
        /// <returns></returns>
        public async Task<IEnumerable<TQWareModel>> GetTQWareModels()
        {

            var  res= await serviceApis.GetTQWareNoBySnApi
                 .WithOAuthBearerToken( AppsettingUnits.Token)
                .PostAsync()
                .ReceiveJson<ResfulModel<IEnumerable<TQWareModel>>>();


            return res.data;
        }


    }
}
